import Vue from 'vue'

import 'normalize.css/normalize.css'// A modern alternative to CSS resets

import ElementUI, {Message} from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n
import VCharts from 'v-charts'

import '@/styles/index.scss' // global css

import 'jquery'
import App from './App'
import router from './router'
import store from './store'
import echarts from 'echarts'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
import dataV from '@jiaminghi/data-view'
import { getToken, setToken, removeToken } from '@/utils/auth'

import '@/icons' // icon
import '@/permission' // permission control

import {getInfo} from '@/api/login' //获取用户信息
import VueCropper from 'vue-cropper'
Vue.use(VueCropper)
Vue.use(VXETable)
Vue.use(dataV)
Vue.use(ElementUI, { locale })
Vue.use(VCharts)
Vue.prototype.$echarts = echarts;
Vue.config.productionTip = false;
// 阻止type="number"鼠标滚动改变数值的监听事件
document.addEventListener('wheel', function(event) {
  // 检查事件目标是否是输入框
  if (event.target.tagName.toLowerCase() === 'input' && event.target.type === 'number') {
    event.preventDefault();
  }
}, { passive: false });

//storage增加过期时间
Storage.prototype.setExpire = (key, value, expire) => {
  let obj = {
    data: value,
    time: Date.now(),
    expire: expire
  };
  //localStorage 设置的值不能为对象,转为json字符串
  localStorage.setItem(key, JSON.stringify(obj));
};
Storage.prototype.getExpire = key => {
  let val = localStorage.getItem(key);
  if (!val) {
    return val;
  }
  val = JSON.parse(val);
  if (Date.now() - val.time > val.expire) {
    localStorage.removeItem(key);
    return null;
  }
  return val.data;
};

new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
});

